package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.SysPermission;
import com.ruoyi.base.service.ISysPermissionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统接口数据Controller
 * 
 * @author ruoyi
 * @date 2025-08-03
 */
@RestController
@RequestMapping("/system/permission")
public class SysPermissionController extends BaseController
{
    @Autowired
    private ISysPermissionService sysPermissionService;

    /**
     * 查询系统接口数据列表
     */
    //@PreAuthorize("@ss.hasPermi('system:permission:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPermission sysPermission)
    {
        startPage();
        List<SysPermission> list = sysPermissionService.selectSysPermissionList(sysPermission);
        return getDataTable(list);
    }

    /**
     * 导出系统接口数据列表
     */
    //@PreAuthorize("@ss.hasPermi('system:permission:export')")
    //@Log(title = "系统接口数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPermission sysPermission)
    {
        List<SysPermission> list = sysPermissionService.selectSysPermissionList(sysPermission);
        ExcelUtil<SysPermission> util = new ExcelUtil<SysPermission>(SysPermission.class);
        util.exportExcel(response, list, "系统接口数据数据");
    }

    /**
     * 获取系统接口数据详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:permission:query')")
    @GetMapping(value = "/getinfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysPermissionService.selectSysPermissionById(id));
    }

    /**
     * 新增系统接口数据
     */
    //@PreAuthorize("@ss.hasPermi('system:permission:add')")
    //@Log(title = "系统接口数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysPermission sysPermission)
    {
        return toAjax(sysPermissionService.insertSysPermission(sysPermission));
    }

    /**
     * 修改系统接口数据
     */
    //@PreAuthorize("@ss.hasPermi('system:permission:edit')")
    //@Log(title = "系统接口数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysPermission sysPermission)
    {
        return toAjax(sysPermissionService.updateSysPermission(sysPermission));
    }

    /**
     * 删除系统接口数据
     */
    //@PreAuthorize("@ss.hasPermi('system:permission:remove')")
    //@Log(title = "系统接口数据", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysPermissionService.deleteSysPermissionByIds(ids));
    }
}
